package com.zxb.base.cms.service.impl;

import com.zxb.base.cms.service.BannerService;
import com.zxb.core.dao.cms.CmsBannerItem;
import com.zxb.core.dao.cms.CmsBannerItemDao;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author
 */
@Service
@AllArgsConstructor
public class BannerServiceImpl implements BannerService {

    private CmsBannerItemDao bannerItemDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void sortItem(String sortStr) {
        String[] sortArr = sortStr.split(",");
        for (String str : sortArr) {
            String[] objArr = str.split("_");
            Long id = Long.parseLong(objArr[0]);
            Integer sort = Integer.parseInt(objArr[1]);
            CmsBannerItem obj = bannerItemDao.getById(id);
            obj.setSort(sort);
            bannerItemDao.updateById(obj);
        }
    }

}
